﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BiografController;
using BiografController.ServiceReference;

namespace BiografGUI
{
    public partial class SalGUI : Form
    {
        private SalController salCtr;
       
        private SalGUI s;
        private int salNr;
        public SalGUI()
        {
            InitializeComponent();
            salCtr = new SalController();
            this.s = this;
            PopulateSalBox();
        }

        private void opretSalButton_Click(object sender, EventArgs e)
        {
            Opret();
        }
        
        private void Opret()
        {
            
            int salId = salCtr.NySal(15, er3DCheckBox.Checked);
            MessageBox.Show(salId.ToString());
            PopulateSalBox();
        }

        private void PopulateSalBox()
        {
            List<Sal> salListe = salCtr.AlleSal();
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = salListe;
            salComboBox.DataSource = bindingSource.DataSource;
            salComboBox.DisplayMember = "salNr";
            salComboBox.ValueMember = "salNr";
        }

        private void salComboBox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            sletSalButton.Enabled = true;
            if (salComboBox.SelectedItem != null)
            {
                Sal salObj = new Sal();
                // FilmId hentes fra filmComboBox.
                salNr = Convert.ToInt32(salComboBox.SelectedValue);
                salNrLabel.Text = "Sal nr: " + salNr;

            }
        }

        private void sletSalButton_Click(object sender, EventArgs e)
        {
            Slet();
            sletSalButton.Enabled = false;
            progressBar2.Value = 0;
        }

        private void Slet()
        {
            try
            {
                salCtr.SletEnSal(salNr);
                PopulateSalBox();
                MessageBox.Show("Salen er slettet");
            }
            catch (Exception)
            {
                MessageBox.Show("Der var problemer");
            }
        }
    }
}
